package io.jee.runshan.service.remote.qiye.impl;

import io.jee.medusa.remote.RemoteConnector;
import io.jee.runshan.domain.remote.qiye.DepartmentCreate;
import io.jee.runshan.domain.remote.qiye.DepartmentList;
import io.jee.runshan.domain.remote.qiye.base.Response;
import io.jee.runshan.domain.remote.qiye.request.DepartmentData;
import io.jee.runshan.service.remote.qiye.IDeptService;
import io.jee.runshan.utils.JsonUtil;
import io.jee.runshan.utils.QiyeConstant;

import org.springframework.stereotype.Component;

@Component
public class DeptServiceImpl implements IDeptService {

	@Override
	public DepartmentList list() {
		String access_token = QiyeConstant.getApptoken();
		String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + access_token + "&id=1";
		return RemoteConnector.post(url, null, DepartmentList.class);
	}

	@Override
	public DepartmentCreate create(DepartmentData data) {
		String access_token = QiyeConstant.getApptoken();
		String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=" + access_token;
		String params = JsonUtil.beanToJson(data);
		return RemoteConnector.post(url, params, DepartmentCreate.class);
	}
	
	@Override
	public Response update(DepartmentData data) {
		String access_token = QiyeConstant.getApptoken();
		String url = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=" + access_token;
		String params = JsonUtil.beanToJson(data);
		return RemoteConnector.post(url, params, Response.class);
	}
	
	@Override
	public Response delete(Integer id) {
		String access_token = QiyeConstant.getApptoken();
		String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=" + access_token + "&id=" + id;
		return RemoteConnector.get(url, null, Response.class);
	}
	
}
